package o;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Shader.TileMode;
import android.os.Build;
import android.os.Build.VERSION;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public final class xb {
    private static final Paint ˊ = new Paint(7);
    private static final Paint ˋ = new Paint(6);
    private static final Paint ˎ = new Paint(7);
    private static final Lock ˏ = (ॱ.contains(Build.MODEL) ? new ReentrantLock() : new d());
    private static final Set<String> ॱ = new HashSet(Arrays.asList(new String[]{"XT1085", "XT1092", "XT1093", "XT1094", "XT1095", "XT1096", "XT1097", "XT1098", "XT1031", "XT1028", "XT937C", "XT1032", "XT1008", "XT1033", "XT1035", "XT1034", "XT939G", "XT1039", "XT1040", "XT1042", "XT1045", "XT1063", "XT1064", "XT1068", "XT1069", "XT1072", "XT1077", "XT1078", "XT1079"}));

    interface c {
        void ˋ(Canvas canvas, Paint paint, RectF rectF);
    }

    class AnonymousClass1 implements c {
        final /* synthetic */ int ˏ;

        AnonymousClass1(int i) {
            this.ˏ = i;
        }

        public void ˋ(Canvas canvas, Paint paint, RectF rectF) {
            canvas.drawRoundRect(rectF, (float) this.ˏ, (float) this.ˏ, paint);
        }
    }

    static final class d implements Lock {
        d() {
        }

        public void lock() {
        }

        public void lockInterruptibly() throws InterruptedException {
        }

        public boolean tryLock() {
            return true;
        }

        public boolean tryLock(long j, @NonNull TimeUnit timeUnit) throws InterruptedException {
            return true;
        }

        public void unlock() {
        }

        @NonNull
        public Condition newCondition() {
            throw new UnsupportedOperationException("Should not be called");
        }
    }

    static {
        ˎ.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    }

    public static Lock ˊ() {
        return ˏ;
    }

    public static Bitmap ˋ(@NonNull uc ucVar, @NonNull Bitmap bitmap, int i, int i2) {
        float f = 0.0f;
        if (bitmap.getWidth() == i && bitmap.getHeight() == i2) {
            return bitmap;
        }
        float height;
        float width;
        Matrix matrix = new Matrix();
        if (bitmap.getWidth() * i2 > bitmap.getHeight() * i) {
            height = ((float) i2) / ((float) bitmap.getHeight());
            width = (((float) i) - (((float) bitmap.getWidth()) * height)) * 0.5f;
        } else {
            height = ((float) i) / ((float) bitmap.getWidth());
            width = 0.0f;
            f = (((float) i2) - (((float) bitmap.getHeight()) * height)) * 0.5f;
        }
        matrix.setScale(height, height);
        matrix.postTranslate((float) ((int) (width + 0.5f)), (float) ((int) (f + 0.5f)));
        Bitmap ˊ = ucVar.ˊ(i, i2, ˎ(bitmap));
        ˋ(bitmap, ˊ);
        ˎ(bitmap, ˊ, matrix);
        return ˊ;
    }

    public static Bitmap ˎ(@NonNull uc ucVar, @NonNull Bitmap bitmap, int i, int i2) {
        if (bitmap.getWidth() != i || bitmap.getHeight() != i2) {
            float min = Math.min(((float) i) / ((float) bitmap.getWidth()), ((float) i2) / ((float) bitmap.getHeight()));
            int round = Math.round(((float) bitmap.getWidth()) * min);
            int round2 = Math.round(((float) bitmap.getHeight()) * min);
            if (bitmap.getWidth() != round || bitmap.getHeight() != round2) {
                Bitmap ˊ = ucVar.ˊ((int) (((float) bitmap.getWidth()) * min), (int) (((float) bitmap.getHeight()) * min), ˎ(bitmap));
                ˋ(bitmap, ˊ);
                if (Log.isLoggable("TransformationUtils", 2)) {
                    Log.v("TransformationUtils", "request: " + i + "x" + i2);
                    Log.v("TransformationUtils", "toFit:   " + bitmap.getWidth() + "x" + bitmap.getHeight());
                    Log.v("TransformationUtils", "toReuse: " + ˊ.getWidth() + "x" + ˊ.getHeight());
                    Log.v("TransformationUtils", "minPct:   " + min);
                }
                Matrix matrix = new Matrix();
                matrix.setScale(min, min);
                ˎ(bitmap, ˊ, matrix);
                return ˊ;
            } else if (!Log.isLoggable("TransformationUtils", 2)) {
                return bitmap;
            } else {
                Log.v("TransformationUtils", "adjusted target size matches input, returning input");
                return bitmap;
            }
        } else if (!Log.isLoggable("TransformationUtils", 2)) {
            return bitmap;
        } else {
            Log.v("TransformationUtils", "requested target size matches input, returning input");
            return bitmap;
        }
    }

    public static Bitmap ˏ(@NonNull uc ucVar, @NonNull Bitmap bitmap, int i, int i2) {
        if (bitmap.getWidth() > i || bitmap.getHeight() > i2) {
            if (Log.isLoggable("TransformationUtils", 2)) {
                Log.v("TransformationUtils", "requested target size too big for input, fit centering instead");
            }
            return ˎ(ucVar, bitmap, i, i2);
        } else if (!Log.isLoggable("TransformationUtils", 2)) {
            return bitmap;
        } else {
            Log.v("TransformationUtils", "requested target size larger or equal to input, returning input");
            return bitmap;
        }
    }

    public static void ˋ(Bitmap bitmap, Bitmap bitmap2) {
        bitmap2.setHasAlpha(bitmap.hasAlpha());
    }

    public static int ˊ(int i) {
        switch (i) {
            case 3:
            case 4:
                return 180;
            case 5:
            case 6:
                return 90;
            case 7:
            case 8:
                return 270;
            default:
                return 0;
        }
    }

    public static Bitmap ˋ(@NonNull uc ucVar, @NonNull Bitmap bitmap, int i) {
        if (!ˎ(i)) {
            return bitmap;
        }
        Matrix matrix = new Matrix();
        ˎ(i, matrix);
        RectF rectF = new RectF(0.0f, 0.0f, (float) bitmap.getWidth(), (float) bitmap.getHeight());
        matrix.mapRect(rectF);
        Bitmap ˊ = ucVar.ˊ(Math.round(rectF.width()), Math.round(rectF.height()), ˎ(bitmap));
        matrix.postTranslate(-rectF.left, -rectF.top);
        ˊ.setHasAlpha(bitmap.hasAlpha());
        ˎ(bitmap, ˊ, matrix);
        return ˊ;
    }

    public static boolean ˎ(int i) {
        switch (i) {
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
                return true;
            default:
                return false;
        }
    }

    public static Bitmap ॱ(@NonNull uc ucVar, @NonNull Bitmap bitmap, int i, int i2) {
        int min = Math.min(i, i2);
        float f = ((float) min) / 2.0f;
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        float max = Math.max(((float) min) / ((float) width), ((float) min) / ((float) height));
        float f2 = ((float) width) * max;
        float f3 = ((float) height) * max;
        max = (((float) min) - f2) / 2.0f;
        float f4 = (((float) min) - f3) / 2.0f;
        RectF rectF = new RectF(max, f4, f2 + max, f3 + f4);
        Bitmap ˎ = ˎ(ucVar, bitmap);
        Bitmap ˊ = ucVar.ˊ(min, min, ˋ(bitmap));
        ˊ.setHasAlpha(true);
        ˏ.lock();
        try {
            Canvas canvas = new Canvas(ˊ);
            canvas.drawCircle(f, f, f, ˊ);
            canvas.drawBitmap(ˎ, null, rectF, ˎ);
            ˏ(canvas);
            if (!ˎ.equals(bitmap)) {
                ucVar.ˏ(ˎ);
            }
            return ˊ;
        } finally {
            ˏ.unlock();
        }
    }

    private static Bitmap ˎ(@NonNull uc ucVar, @NonNull Bitmap bitmap) {
        Config ˋ = ˋ(bitmap);
        if (ˋ.equals(bitmap.getConfig())) {
            return bitmap;
        }
        Bitmap ˊ = ucVar.ˊ(bitmap.getWidth(), bitmap.getHeight(), ˋ);
        new Canvas(ˊ).drawBitmap(bitmap, 0.0f, 0.0f, null);
        return ˊ;
    }

    @NonNull
    private static Config ˋ(@NonNull Bitmap bitmap) {
        if (VERSION.SDK_INT < 26 || !Config.RGBA_F16.equals(bitmap.getConfig())) {
            return Config.ARGB_8888;
        }
        return Config.RGBA_F16;
    }

    public static Bitmap ॱ(@NonNull uc ucVar, @NonNull Bitmap bitmap, int i) {
        aas.ˏ(i > 0, "roundingRadius must be greater than 0.");
        return ˋ(ucVar, bitmap, new AnonymousClass1(i));
    }

    private static Bitmap ˋ(@NonNull uc ucVar, @NonNull Bitmap bitmap, c cVar) {
        Config ˋ = ˋ(bitmap);
        Bitmap ˎ = ˎ(ucVar, bitmap);
        Bitmap ˊ = ucVar.ˊ(ˎ.getWidth(), ˎ.getHeight(), ˋ);
        ˊ.setHasAlpha(true);
        Shader bitmapShader = new BitmapShader(ˎ, TileMode.CLAMP, TileMode.CLAMP);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setShader(bitmapShader);
        RectF rectF = new RectF(0.0f, 0.0f, (float) ˊ.getWidth(), (float) ˊ.getHeight());
        ˏ.lock();
        try {
            Canvas canvas = new Canvas(ˊ);
            canvas.drawColor(0, Mode.CLEAR);
            cVar.ˋ(canvas, paint, rectF);
            ˏ(canvas);
            if (!ˎ.equals(bitmap)) {
                ucVar.ˏ(ˎ);
            }
            return ˊ;
        } finally {
            ˎ = ˏ;
            ˎ.unlock();
        }
    }

    private static void ˏ(Canvas canvas) {
        canvas.setBitmap(null);
    }

    @NonNull
    private static Config ˎ(@NonNull Bitmap bitmap) {
        return bitmap.getConfig() != null ? bitmap.getConfig() : Config.ARGB_8888;
    }

    private static void ˎ(@NonNull Bitmap bitmap, @NonNull Bitmap bitmap2, Matrix matrix) {
        ˏ.lock();
        try {
            Canvas canvas = new Canvas(bitmap2);
            canvas.drawBitmap(bitmap, matrix, ˋ);
            ˏ(canvas);
        } finally {
            ˏ.unlock();
        }
    }

    @VisibleForTesting
    static void ˎ(int i, Matrix matrix) {
        switch (i) {
            case 2:
                matrix.setScale(SizeModifier.STABLE_STATE_SCALE, 1.0f);
                return;
            case 3:
                matrix.setRotate(180.0f);
                return;
            case 4:
                matrix.setRotate(180.0f);
                matrix.postScale(SizeModifier.STABLE_STATE_SCALE, 1.0f);
                return;
            case 5:
                matrix.setRotate(90.0f);
                matrix.postScale(SizeModifier.STABLE_STATE_SCALE, 1.0f);
                return;
            case 6:
                matrix.setRotate(90.0f);
                return;
            case 7:
                matrix.setRotate(-90.0f);
                matrix.postScale(SizeModifier.STABLE_STATE_SCALE, 1.0f);
                return;
            case 8:
                matrix.setRotate(-90.0f);
                return;
            default:
                return;
        }
    }
}
